
clear all
cd "${data}"	
use "data1.dta", clear

drop if missing(IMD3007_, daysafter, IMD5012_, singleparty, country_, election_)

* FIGURE 4 - Perceptual Accuracy Decreases as Time Passes Since Election for Plausibly Stable Parties and Others


*main model run only for parties in single-party governments 

gen daysafter_singleparty = daysafter if singleparty==1
gen daysafter_notsingleparty = daysafter if singleparty==0

eststo m1: mixed IMD3007_ c.IMD5012_##c.daysafter if singleparty==1 || election_: c.daysafter
margins, dydx(IMD5012_) at(daysafter=(0(30)270))  post // among single party government in a single party government-produced election
marginsplot, plot1opts(color(gs5) lpattern(shortdash)) recast(line) recastci(rarea) level(95) yline(0, lpattern(solid)) ci1opts(color(gs10*.8%50)) addplot(hist daysafter_singleparty, percent color(gs5%20) yaxis(2) ytitle("percent", size(3) axis(2)) yscale(range(0(5)25) axis(2) alt)) legend(off) ytitle("AME of change in expert party position", size(2.5)) title("") xscale(range(0(100)300)) xlabel(0(100)300) 


graph save "${figures}/singlepartgov.gph", replace



*main model run only for opposition parties or coalition partners

eststo m2: mixed c.IMD3007_ c.daysafter##c.IMD5012_ if singleparty==0 || country_: || election_:  || respondent: IMD5012_
margins, dydx(IMD5012_) at(daysafter=(0(30)300))  post // among not single party government in a single party government-produced election
marginsplot, plot1opts(color(gs5) lpattern(shortdash)) recast(line) recastci(rarea) level(95) yline(0, lpattern(solid)) ci1opts(color(gs10*.8%50)) addplot(hist daysafter_notsingleparty, percent color(gs5%20) yaxis(2) ytitle("percent", size(3) axis(2)) yscale(range(0(5)25) axis(2) alt)) legend(off) ytitle("AME of change in expert party position", size(2.5)) title("") xscale(range(0(100)300)) xlabel(0(100)300) 

graph save "${figures}/notsinglepartgov.gph", replace
 
 cd "${figures}"	
 graph combine singlepartgov.gph notsinglepartgov.gph, ycommon xsize(10) ysize(6) b1("days since election") l1("AME of change in expert party position")
 graph save "${figures}/figure4.gph", replace
 graph export "${figures}/figure4.png", replace
 
 
 
cd "${tables}"	

esttab m1 m2 using tableR1.tex , replace ///
b(3) se(3) nogap transform(ln*: exp(2*@) 2*exp(2*@))







